#ifndef _MEDIAINPUT_HH
#define _MEDIAINPUT_HH

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <MediaSink.hh>

class MediaInput: public Medium {
public:
  static MediaInput* createNew(UsageEnvironment& env);

  FramedSource* videoSource();
  FramedSource* audioSource();

private:
  MediaInput(UsageEnvironment& env); // called only by createNew()
  virtual ~MediaInput();

private:
  friend class RealVideoSource;
  friend class RealAudioSource;
  static FramedSource* VideoSource;
  static FramedSource* AudioSource;
};

// Functions to set the optimal buffer size for RTP sink objects.
// These should be called before each RTPSink is created.
#define AUDIO_MAX_FRAME_SIZE 20480
#define VIDEO_MAX_FRAME_SIZE 512000
inline void setAudioRTPSinkBufferSize() { OutPacketBuffer::maxSize = AUDIO_MAX_FRAME_SIZE; }
inline void setVideoRTPSinkBufferSize() { OutPacketBuffer::maxSize = VIDEO_MAX_FRAME_SIZE; }

class RealMediaSource: public FramedSource {
protected:
  RealMediaSource(UsageEnvironment& env, MediaInput& input);
  virtual ~RealMediaSource();

  int mediaConnect (unsigned short port);

  virtual void readFromFile() = 0;

private: // redefined virtual functions:
  virtual void doGetNextFrame();

private:
  void incomingDataHandler1();
  static void incomingDataHandler(RealMediaSource* source, int /*mask*/);

protected:
  MediaInput& fInput;
  int fFileNo;
};

class RealVideoSource: public RealMediaSource {
public:
	RealVideoSource(UsageEnvironment& env, MediaInput& input);
	virtual ~RealVideoSource();

protected: // redefined virtual functions:
	virtual void readFromFile();
};

class RealAudioSource: public RealMediaSource {
public:
	RealAudioSource(UsageEnvironment& env, MediaInput& input);
	virtual ~RealAudioSource();

protected: // redefined virtual functions:
	virtual void readFromFile();
};

#endif
